﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Metadata.Edm;
using System.Linq;
using System.Web;


namespace LeadCRM.Entities
{
    public class LeadCRMContext : DbContext
    {
        public DbSet<User> User { get; set; }
        public DbSet<CustomerTypeMaster> CustomerTypeMaster { get; set; }
        public DbSet<Lead> Lead { get; set; }
        public DbSet<Menu> Menu { get; set; }
        public DbSet<Role> Roles { get; set; }

        public LeadCRMContext()
            : base("LeadCRMEntities")
        {
            this.Configuration.LazyLoadingEnabled = true;

        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            Database.SetInitializer(new MyDbContextInitializer());

            base.OnModelCreating(modelBuilder);
        }
        static void MyDbContext()
        {
            Database.SetInitializer(new MyDbContextInitializer());
        }

    }

    public class MyDbContextInitializer : DropCreateDatabaseIfModelChanges<LeadCRMContext>
    {
        protected override void Seed(LeadCRMContext dbContext)
        {
            // seed data
            #region Add Users
            
            WebSecurity.Register("NitinJain", "12345678", "Nitin403@hotmail.com"
                , true, "Nitin", "Jain");

            WebSecurity.Register("Admin", "12345678", "Admin@valuesDesign.com"
                , true, "Nitin", "Jain");

            WebSecurity.Register("Host", "12345678", "Host@hotmail.com"
                , true, "Nitin", "Jain");

            WebSecurity.Register("Host1", "12345678", "Host1@hotmail.com"
                , true, "Nitin", "Jain");

            WebSecurity.Register("Host2", "12345678", "Host2@hotmail.com"
                , true, "Nitin", "Jain");

            WebSecurity.Register("Host3", "12345678", "Host3@hotmail.com"
                , true, "Nitin", "Jain");

            WebSecurity.Register("Host4", "12345678", "Host4@hotmail.com"
                , true, "Nitin", "Jain");

            WebSecurity.Register("Host5", "12345678", "Host5@hotmail.com"
                , true, "Nitin", "Jain");


            WebSecurity.Register("Host6", "12345678", "Host6@hotmail.com"
                , true, "Nitin", "Jain");

            WebSecurity.Register("Host7", "12345678", "Host7@hotmail.com"
                , true, "Nitin", "Jain");

            WebSecurity.Register("Host8", "12345678", "Host8@hotmail.com"
                , true, "Nitin", "Jain");

            WebSecurity.Register("Host9", "12345678", "Host9@hotmail.com"
                , true, "Nitin", "Jain");
            #endregion

            #region Add Menu
            dbContext.Menu.Add(
                    new Menu
                    {
                        MenuName = "Home",
                        MenuURL = "/Home/Index",
                        Description = "This is Home Page",
                        OrderNo = 1
                        
                    });
            
            dbContext.Menu.Add(new Menu
            {
                MenuName = "Customer Type",
                MenuURL = "/Masters/CustomerType",
                Description = "Change Customer Type Info",
                OrderNo = 2
            });

            dbContext.Menu.Add(new Menu
            {
                MenuName = "Menu Master",
                MenuURL = "/Masters/MenuMaster",
                Description = "Menu Master",
                OrderNo = 3
            });
            dbContext.Menu.Add(new Menu
            {
                MenuName = "Manage User",
                MenuURL = "/Account/ManageUsers",
                Description = "Manage User",
                OrderNo = 4
            }); 
            #endregion

            #region Add Customer Type
            dbContext.CustomerTypeMaster.Add(
                    new CustomerTypeMaster
                        {
                            CreatedBy = 1,
                            CreatedOn = DateTime.Now,
                            CustomerTypeName = "Hotels",
                            IsDeleted = false,
                            LastModifiedBy = null,
                            LastModifiedOn = null
                        }
                    );
            dbContext.CustomerTypeMaster.Add(
                new CustomerTypeMaster
                {
                    CreatedBy = 1,
                    CreatedOn = DateTime.Now,
                    CustomerTypeName = "Travel",
                    IsDeleted = false,
                    LastModifiedBy = null,
                    LastModifiedOn = null
                }
                ); 
            #endregion



            base.Seed(dbContext);
        }
    }
}